{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0",
   "metadata": {},
   "source": [
    "<a href=\"https://githubtocolab.com/gee-community/geemap/blob/master/docs/notebooks/117_fishnet.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open in Colab\"/></a>\n",
    "\n",
    "**Creating a fishnet based on an input vector dataset**\n",
    "\n",
    "Uncomment the following line to install [geemap](https://geemap.org) if needed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# !pip install -U geemap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2",
   "metadata": {},
   "outputs": [],
   "source": [
    "import ee\n",
    "import geemap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map = geemap.Map()\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4",
   "metadata": {},
   "source": [
    "Simply draw a rectangle or polyon on the map use to used as an ROI."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = Map.user_roi\n",
    "\n",
    "if data is None:\n",
    "    data = ee.Geometry.BBox(-112.8089, 33.7306, -88.5951, 46.6244)\n",
    "    Map.addLayer(data, {}, \"ROI\")\n",
    "    Map.user_roi = None\n",
    "\n",
    "Map.centerObject(data)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6",
   "metadata": {},
   "source": [
    "The input data can also be a file path or HTTP URL to a vector dataset. There are two ways to create a fishnet: specifying horizontal and vertical intervals or the number of rows and columns.\n",
    "\n",
    "Let's create a fishnet by specifying horizontal and vertical intervals in degrees."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7",
   "metadata": {},
   "outputs": [],
   "source": [
    "fishnet = geemap.fishnet(data, h_interval=2.0, v_interval=2.0, delta=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.addLayer(fishnet, {}, \"Fishnet 1\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9",
   "metadata": {},
   "source": [
    "Draw another polygon on the map."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "10",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = Map.user_roi\n",
    "\n",
    "if data is None:\n",
    "    data = ee.Geometry.Polygon(\n",
    "        [\n",
    "            [\n",
    "                [-64.602356, -1.127399],\n",
    "                [-68.821106, -12.625598],\n",
    "                [-60.647278, -22.498601],\n",
    "                [-47.815247, -21.111406],\n",
    "                [-43.860168, -8.913564],\n",
    "                [-54.582825, -0.775886],\n",
    "                [-60.823059, 0.454555],\n",
    "                [-64.602356, -1.127399],\n",
    "            ]\n",
    "        ]\n",
    "    )\n",
    "    Map.addLayer(data, {}, \"ROI2\")\n",
    "\n",
    "Map.centerObject(data)\n",
    "Map"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "11",
   "metadata": {},
   "source": [
    "Let's create another fishnet by specifying the number of rows and columns."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12",
   "metadata": {},
   "outputs": [],
   "source": [
    "fishnet = geemap.fishnet(data, rows=6, cols=8, delta=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "13",
   "metadata": {},
   "outputs": [],
   "source": [
    "Map.addLayer(fishnet, {}, \"Fishnet 2\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
